package cn.jingyuan.swan.gw.web.endpoint;

import cn.jingyuan.swan.cloud.core.Result;
import cn.jingyuan.swan.cloud.core.ResultUtils;
import cn.jingyuan.swan.gw.locator.RemoteRouteLocator;
import cn.jingyuan.swan.gw.locator.ResourceLocator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 刷新路由
 */
@Slf4j
@Component
@Endpoint(id = "routes-refresh")
public class RoutesRefreshEndpoint {
    // http://mmnnaa.com/?p=1125

    @Resource
    RemoteRouteLocator routeLocator;

    @Resource
    ResourceLocator resourceLocator;

    @WriteOperation(produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Object> refresh() {
        routeLocator.doRefresh();
        resourceLocator.doRefresh();

        return ResultUtils.ok();
    }

}
